Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change multithreading backend to Base.Threads #153

Merged
merged 5 commits into from
Jul 24, 2024
Merged

Conversation

kaipartmann
Copy link
Owner

The multithreading backend is changed. All previous Polyester.@batch calls are replaced with Threads.@threads :static calls. This is now possible due to the changes in trixi-framework/PointNeighbors.jl#61 with PointNeighbors.jl v0.4.5.

As shown in the PR, this will result in a improved performance.

Benchmark with 64 Threads:

using Peridynamics

function sphere_impact(; ns=6, np=3, path)
    Ø = 0.15
    ΔX0_sphere = Ø / ns
    pos_sphere, vol_sphere = uniform_sphere(Ø, ΔX0_sphere; center_z=Ø / 2 + ΔX0_sphere)
    sphere = Body(BBMaterial{EnergySurfaceCorrection}(), pos_sphere, vol_sphere)
    failure_permit!(sphere, false)
    material!(sphere; horizon=3.1ΔX0_sphere, E=210e9, rho=8000, Gc=2000)
    velocity_ic!(sphere, :all_points, :z, -20)
    lxy, lz = 2.0, 0.1
    ΔX0_plate = lz / np
    pos_plate, vol_plate = uniform_box(lxy, lxy, lz, ΔX0_plate; center_z=-lz / 2)
    plate = Body(BBMaterial{EnergySurfaceCorrection}(), pos_plate, vol_plate)
    material!(plate; horizon=3.1ΔX0_plate, E=27e9, rho=2700, Gc=10)
    ms = MultibodySetup(:sphere => sphere, :plate => plate)
    contact!(ms, :sphere, :plate; radius=min(ΔX0_sphere, ΔX0_plate))
    vv = VelocityVerlet(steps=2000)
    job = Job(ms, vv; path=path)
    @time submit(job)
    return nothing
end

##
path = "results/benchmarks/sphere_impact"
rm(path; recursive=true, force=true)
sphere_impact(; path) # compilation
sphere_impact(; ns=20, np=8, path) # work

Due to the Polyester-Threads mixing issue I thought it could be a good idea to also use Polyester.@batch, so it is used for every multithreading loop in the package in v0.3.0:

## Peridynamics.jl v0.3.0 - everywhere using Polyester.@batch
# compilation:
# 89.256836 seconds (47.14 M allocations: 14.914 GiB, 0.66% gc time, 7.14% compilation time)
# work:
# 45.514108 seconds (40.16 M allocations: 128.786 GiB, 8.94% gc time)

However, I found out this was the reason my parallel performance for single body simulations is not as good as before. When changing all Polyester.@batch statements in Peridynamics.jl to @threads :static calls, the performance of contact simulations also improves (if PointNeighbors.jl also uses @threads :static):

## Peridynamics.jl v0.3.1-DEV - everywhere using Threads.@threads :static
## PointNeighbors.jl v0.4.5: update_grid!(...; parallelization_backend=ThreadsStaticBackend())
# compilation:
# 106.717161 seconds (54.34 M allocations: 15.806 GiB, 0.61% gc time, 5.13% compilation time)
# work:
# 39.184317 seconds (48.59 M allocations: 129.752 GiB, 9.53% gc time)

@kaipartmann kaipartmann added performance Anything relevant for performance parallelization Related to MPI or threading etc. dependencies Pull requests that update a dependency file labels Jul 24, 2024
Copy link

codecov bot commented Jul 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.32%. Comparing base (1a8116f) to head (ddeab3a).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #153   +/-   ##
=======================================
  Coverage   90.32%   90.32%           
=======================================
  Files          43       43           
  Lines        4040     4040           
=======================================
  Hits         3649     3649           
  Misses        391      391           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kaipartmann kaipartmann merged commit 564f47b into main Jul 24, 2024
8 checks passed
@kaipartmann kaipartmann deleted the threads_static branch July 24, 2024 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file parallelization Related to MPI or threading etc. performance Anything relevant for performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant